<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    [#include "/includes/header.html" /]
    <style type="text/css">
        .dd {
            float: left;
            width: 20%;
        }

        .dd-handle-bk-color {
            background: #d4d4d4;
        }
    </style>
    <script type="text/javascript">
        var qname = "";
        $(document).ready(function () {
            $("#myqueryBtn").click(function () {
                qname = $("#q_pond_txt").val() == "输入签到名称" ? "" : $("#q_pond_txt").val();
                searchpromotions();
            });
            //批量删除
            $("#mypromotionDelBtn").click(function () {
                var count = TBatch.getCheckedCount();
                if (count == 0) {
                    obz.showMessage("请选择一个活动");
                } else {
                    obz.showMessage("确定删除吗？删除后不可恢复，请谨慎操作！", function () {
                        var ids = TBatch.getChecked();
                        obz.ajaxJson(obz.ctx + "/promotion/del", {ids: ids}, function (resp) {
                            if (resp.code == 200) {
                                searchpromotions();
                            }
                        });
                    });
                }
            });

            searchpromotions();
        });

        var pageClick = function (pageNo) {
            searchpromotions(pageNo);
        }

        var searchpromotions = function (currPage) {
            var params = {};
            //其他查询条件
            if (currPage) {
                params.page = currPage;
            }
            params.qname = qname;
            params.type = $("#a_type_sel").val();
            params.status = $("#a_status_sel").val();

            $("#mainTable").mask("加载中...");
            var url = obz.ctx + "/promotion/list";
            obz.ajaxJson(url, params, function (resp) {
                $("#mainTable").unmask();
                var result = resp.data;
                $(".promotionLotGrid").empty();
                if (currPage) {
                    $("#pager").pager({
                        pagenumber: currPage,
                        recordcount: result.totalRow,
                        pagesize: result.pageSize,
                        recordtext: '共 {0} 页, {1} 条记录',
                        buttonClickCallback: pageClick
                    });
                } else {
                    $("#pager").pager({
                        recordcount: result.totalRow,
                        pagesize: result.pageSize,
                        recordtext: '共 {0} 页, {1} 条记录',
                        buttonClickCallback: pageClick
                    });
                }
                var dataList = result.list;
                if (dataList.length > 0) {
                    for (var i = 0; i < dataList.length; i++) {
                        var _row = dataList[i];
                        var trHtml = obz.dataTemplate4obj($("#promotion_table_tr_tpl").html(), _row);
                        $(".promotionLotGrid").append(trHtml);
                    }
                    TBatch.checkCheckbox();
                    TBatch.initCheckboxClick();
                    TBatch.initOptEvent(ActivityTableOpt.init());
                } else {
                    $(".promotionLotGrid").append($("#table_noresult_tr_tpl").html());
                }
            });
        }

        //=============================表格操作事件开始=============================================
        var ActivityTableOpt = {
            edit: function (param) {
                var id = param[1];
                location.href = obz.ctx + "/promotion/set/?pid=" + id;
            },
            del: function (param) {
                obz.showMessage("确定删除吗？删除后不可恢复，请谨慎操作！", function () {
                    var ids = param[1];
                    obz.ajaxJson(obz.ctx + "/promotion/del", {ids: ids}, function (resp) {
                        if (resp.code == 200) {
                            searchpromotions();
                        }
                    });
                });
                return false;
            },
            init: function () {
                var optArray = new Array();
                optArray.push(this.edit);
                optArray.push(this.del);
                return optArray;
            }
        }
        //=============================表格操作事件结束=============================================
    </script>
</head>
<body class="fixed-sidebar full-height-layout gray-bg" style="overflow:hidden">
[#include "/includes/menus.html" /]
<div class="wrapper wrapper-content">
    <div class="row content-tabs">
        <nav class="page-tabs J_menuTabs">
            <div class="page-tabs-content" style="margin-left: 0px;">
                <a href="${webctx}/promotion" class="J_menuTab active">限时打折</a>
                <!-- <a href="${webctx}/cashback" class="J_menuTab">订单返现</a> -->
                <a href="${webctx}/reward" class="J_menuTab">满减送</a>
            </div>
        </nav>
    </div>
    <div id="tableList" class="content row ibox-content" style="padding-top: 10px;">
        <div class="panel-body">
            <a href="${webctx}/promotion/set" class="btn btn-success">新建限时折扣</a>
        </div>

        <!-- <table class="table-striped" width="100%" border="0" cellspacing="1" cellpadding="0">
            <tr>
                <td colspan="3" style="text-align: left;">&nbsp;&nbsp;
                    <input type="text" name="q_pond_txt" id="q_pond_txt" class="input-text"
                        style="width:190px; color:#DFDFDF" value="输入签到名称"
                        onfocus="if(this.value=='输入签到名称'){this.value=''};this.style.color='black';"
                        onblur="if(this.value==''||this.value=='输入签到名称'){this.value='输入签到名称';this.style.color='#DFDFDF';}"/>
                    <select id="a_status_sel" style="width: 102px">
                        <option value="-1" selected="selected">全部</option>
                        <option value="3">进行中</option>
                        <option value="2">已结束</option>
                    </select>
                    <button id="myqueryBtn" class="btn btn-success">查询</button>
                </td>
            </tr>
        </table> -->
        <div id="promotionToolsbar" class="panel-body">
            <div id="pager" class="jqpager" style="margin-bottom: 1px;"></div>
            <!-- <div style="float: left;">
                <button id="mypromotionDelBtn" class="btn btn-info">批量删除</button>
            </div> -->
        </div>
        <table class="table table-striped table-bordered bootstrap-datatable datatable" id="mainTable" border="0">
            <thead>
            <tr>
                <th>
                    <input type="checkbox" id="all" title="全选/反选" style="margin-right: 4px; vertical-align: middle;"/>
                </th>
                <th>
                    <span style="vertical-align: middle;">&nbsp;&nbsp;活动名称</span>
                </th>
                <th>开始时间</th>
                <th>结束时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody class="promotionLotGrid">
            </tbody>
        </table>
    </div>
</div>

<!-- 模板开始 -->
<script type="text/template" id="promotion_table_tr_tpl">
    <tr class="package">
        <td>
            <input type="checkbox" class="commchk" id="checkbox_{promotionId}"
                   style="margin-right: 4px; vertical-align: middle;"/>
        </td>
        <td>
            <span style="margin-right: 5px; margin-left: 2px; vertical-align: middle;">{promotionName}</span>
        </td>
        <td><span>{startDate}</span></td>
        <td><span>{endDate}</span></td>
        <td>
            &nbsp;<a id="edit_{promotionId}" href="javascript:void(0)" style="text-decoration: underline;">编辑</a>
            &nbsp;<a id="del_{promotionId}" href="javascript:void(0)" style="text-decoration: underline;">删除</a>
        </td>
    </tr>
</script>
<script type="text/template" id="table_noresult_tr_tpl">
    <tr class="package">
        <td class="center" colspan="5">
            没有结果集，现在去创建吧，
            <a href="${webctx}/promotion/set" style="text-decoration: underline;">去创建</a>
        </td>
    </tr>
</script>
[#include "/includes/footer.html" /]
<script>
    Template.init("#menu-discount");
</script>
</body>
</html>